<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <title>Document</title>
</head>

<body>
    <img src="./loading.gif" alt="" style="display: none;" id="loading" />
    <input type="file" id="file1" />
    <button id="btnUpload">上传文件</button>
    <script type="text/javascript" src="./lib/jquery.js"></script>
    <script type="text/javascript">
        $("#btnUpload").click(function() {
            var file = $("#file1").get(0).files[0];
            //get(0)将JQ对象转成dom对象
            if (!file) {
                alert("请选择文件");
            }
            var fd = new FormData();
            fd.append("avatar", file);
            $.ajax({
                type: "POST",
                url: "http://www.liulongbin.top:3006/api/upload/avatar",
                data: fd,
                processData: false,
                contentType: false,
                success: function(res) {
                    console.log(res);
                },
            });
        });
    </script>
</body>

</html>